package com.xyc.servlet;

import com.xyc.mapper.OrderMapper;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;

@WebServlet("/total")
public class TotalServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        System.out.println("total....");

        req.setCharacterEncoding("utf-8");

        ApplicationContext ctx = new ClassPathXmlApplicationContext("spring-dao.xml");
        OrderMapper orderMapper = ctx.getBean("orderMapper", OrderMapper.class);
        Integer total = orderMapper.total();

        System.out.println("total:"+total);

        HttpSession session = req.getSession();
        session.setAttribute("total",total);

        resp.sendRedirect("buycar.jsp");
    }
}
